#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename:   07-stopSvc-industrial.sh
# Version:    1.0
# Date:       2020/05/15
# Author:     Lz
# Email:      lz843723683@gmail.com
# History：     
#             Version 1.0, 2020/05/15
# Function:   默认关闭服务
# Out:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

## TODO : 测试收尾清除工作
#
StopSvcClean_FTGW_INDUSTRIAL(){
	return $TPASS
}


## TODO: 调用程序退出函数
#    In: $1 => 调用脚本结果值
StopSvcExit_FTGW_INDUSTRIAL(){
        # 调用退出函数，其中调用了clean相关函数
	Exit_FTLIB ${1}
}


## TODO: 用户界面
#
StopSvcUSAGE_FTGW_INDUSTRIAL(){
	USAGE_FTLIB "金风工控版 - 默认关闭服务"
}


## TODO : 测试前的初始化 
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other=> TCONF
StopSvcInit_FTGW_INDUSTRIAL(){
        # 调用初始化函数
	Init_FTLIB "StopSvcClean_FTGW_INDUSTRIAL"
        # 调用用户界面函数
 	StopSvcUSAGE_FTGW_INDUSTRIAL
}


## TODO ：默认关闭或者未提供服务：bluetooth、cups 、postfix、rpcbind、avihi-daemon
#
StopSvcTest01_FTGW_INDUSTRIAL(){
        local svcArr="bluetooth cups postfix rpcbind avihi-daemon"

        SvcEnableArr_FTLIB "noEnable" "no" "$svcArr"
        RetParse_FTLIB "默认关闭或者未提供以下服务: ${svcArr}" "False"
}


## TODO ：去掉Agent.jar服务
#
StopSvcTest02_FTGW_INDUSTRIAL(){
	local flag="agent.jar"

        # 测试目前正在运行Agent.jar
	echo "ps -aux | grep -i ${flag}"
        ps -aux | grep -i ${flag}
        ps -aux | grep -i ${flag} | grep -q "java -jar"
	if [ $? -eq 0 ];then
		# 启动了agent.jar进程
		false
	else
		# 未启动agent.jar进程
		true
	fi
        RetParse_FTLIB "未运行 ${flag} 进程" "False"
}


## TODO : Main
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other => TCONF
StopSvcMain_FTGW_INDUSTRIAL(){
	StopSvcInit_FTGW_INDUSTRIAL

	StopSvcTest01_FTGW_INDUSTRIAL

	StopSvcTest02_FTGW_INDUSTRIAL

	return ${TPASS}	
}

StopSvcMain_FTGW_INDUSTRIAL
StopSvcExit_FTGW_INDUSTRIAL $?
